home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 October / CHIP Turkiye Ekim 2000.iso / prog / naps / 04 / setup.exe / Gnucleus / PrefDownload.cpp < prev    next >
C/C++ Source or Header  |  2000-06-24  |  6KB  |  239 lines

  1. /********************************************************************************
  2.  
  3.     Gnucleus - A node application for the Gnutella network
  4.     Copyright (C) 2000 John Marshall
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19.     For support, questions, comments, etc...
  20.     E-Mail: 
  21.         swabby@c0re.net
  22.     
  23.     Address:
  24.         21 Cadogan Way
  25.         Nashua, NH, USA 03062
  26.  
  27. ********************************************************************************/
  28.  
  29. // PrefDownload.cpp : implementation file
  30. //
  31.  
  32. #include "stdafx.h"
  33. #include "Gnucleus.h"
  34. #include "GnucleusDoc.h"
  35. #include "PrefDownload.h"
  36.  
  37. #ifdef _DEBUG
  38. #define new DEBUG_NEW
  39. #undef THIS_FILE
  40. static char THIS_FILE[] = __FILE__;
  41. #endif
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CPrefDownload property page
  45.  
  46. IMPLEMENT_DYNCREATE(CPrefDownload, CPropertyPage)
  47.  
  48. CPrefDownload::CPrefDownload() : CPropertyPage(CPrefDownload::IDD)
  49. {
  50.     Doc = NULL;
  51.  
  52.     //{{AFX_DATA_INIT(CPrefDownload)
  53.     //}}AFX_DATA_INIT
  54. }
  55.  
  56. CPrefDownload::~CPrefDownload()
  57. {
  58. }
  59.  
  60. void CPrefDownload::DoDataExchange(CDataExchange* pDX)
  61. {
  62.     CPropertyPage::DoDataExchange(pDX);
  63.     //{{AFX_DATA_MAP(CPrefDownload)
  64.     DDX_Control(pDX, IDC_CHECK_RESUME, m_chkResume);
  65.     DDX_Control(pDX, IDC_EDIT_TIMEOUT_DL, m_ebTimeoutDL);
  66.     DDX_Control(pDX, IDC_CHECK_CLEAR_DL, m_chkClearDL);
  67.     DDX_Control(pDX, IDC_EDIT_SAVEDIR, m_ebSaveDir);
  68.     DDX_Control(pDX, IDC_CHECK_MAX_DL, m_chkMaxDL);
  69.     DDX_Control(pDX, IDC_EDIT_MAX_DL, m_ebMaxDL);
  70.     //}}AFX_DATA_MAP
  71. }
  72.  
  73.  
  74. BEGIN_MESSAGE_MAP(CPrefDownload, CPropertyPage)
  75.     //{{AFX_MSG_MAP(CPrefDownload)
  76.     ON_EN_CHANGE(IDC_EDIT_SAVEDIR, OnChangeEditSavedir)
  77.     ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
  78.     ON_BN_CLICKED(IDC_CHECK_MAX_DL, OnCheckMaxDl)
  79.     ON_EN_CHANGE(IDC_EDIT_MAX_DL, OnChangeEditMaxDl)
  80.     ON_BN_CLICKED(IDC_CHECK_CLEAR_DL, OnCheckClearDl)
  81.     ON_EN_CHANGE(IDC_EDIT_TIMEOUT_DL, OnChangeEditTimeoutDl)
  82.     ON_BN_CLICKED(IDC_CHECK_RESUME, OnCheckResume)
  83.     //}}AFX_MSG_MAP
  84. END_MESSAGE_MAP()
  85.  
  86. /////////////////////////////////////////////////////////////////////////////
  87. // CPrefDownload message handlers
  88.  
  89. BOOL CPrefDownload::OnInitDialog() 
  90. {
  91.     CPropertyPage::OnInitDialog();
  92.     
  93.     Doc = (CGnucleusDoc *) ((CGnucleusApp *) AfxGetApp())->MasterDoc;
  94.     
  95.     // Save downloads setting
  96.     m_ebSaveDir.SetWindowText(Doc->m_DownloadDir);
  97.  
  98.     // Max simultaneous downloads
  99.     if(Doc->m_MaxDownloads)
  100.     {
  101.         m_chkMaxDL.SetCheck(1);
  102.         m_ebMaxDL.SetWindowText( DWrdtoStr(Doc->m_MaxDownloads) );
  103.     }
  104.     else
  105.     {
  106.         m_ebMaxDL.SetWindowText("Unlim.");
  107.         m_ebMaxDL.EnableWindow(FALSE);
  108.     }
  109.  
  110.     // Auto clear downloads
  111.     if(Doc->m_AutoClearDL)
  112.         m_chkClearDL.SetCheck(1);
  113.  
  114.     // Timeout of download length
  115.     m_ebTimeoutDL.SetWindowText( DWrdtoStr(Doc->m_TimeoutDownload) );
  116.  
  117.     // Resume downloads
  118.     if(Doc->m_ResumeDL)
  119.         m_chkResume.SetCheck(1);
  120.  
  121.     return TRUE;  // return TRUE unless you set the focus to a control
  122.                   // EXCEPTION: OCX Property Pages should return FALSE
  123. }
  124.  
  125. void CPrefDownload::OnChangeEditSavedir() 
  126. {
  127.     SetModified();    
  128. }
  129.  
  130. void CPrefDownload::OnButtonBrowse() 
  131. {
  132.     char *Directory = new char[255];
  133.  
  134.     LPBROWSEINFO Settings = new BROWSEINFO;
  135.     Settings->hwndOwner = m_hWnd;
  136.     Settings->pidlRoot  = NULL;
  137.     Settings->pszDisplayName = Directory;
  138.     Settings->lpszTitle = "Save Downloads to...";
  139.     Settings->ulFlags   = BIF_RETURNONLYFSDIRS;
  140.     Settings->lpfn      = NULL;
  141.     Settings->lParam    = NULL;
  142.     Settings->iImage    = NULL;
  143.  
  144.     LPCITEMIDLIST FolderID = SHBrowseForFolder(Settings);
  145.     delete Settings;
  146.  
  147.  
  148.     if(FolderID) // if cancel was hit, leave the current directory setting
  149.     {
  150.         SHGetPathFromIDList(FolderID, Directory);
  151.         
  152.         CString File = Directory;
  153.         
  154.         m_ebSaveDir.SetWindowText(File);
  155.  
  156.         SetModified();
  157.     }
  158.  
  159.     delete [] Directory;
  160. }
  161.  
  162. void CPrefDownload::OnCheckMaxDl() 
  163. {
  164.     if(m_chkMaxDL.GetCheck())
  165.     {
  166.         m_ebMaxDL.SetWindowText( DWrdtoStr(Doc->m_MaxDownloads) );
  167.         m_ebMaxDL.EnableWindow();
  168.     }
  169.     else
  170.     {
  171.         m_ebMaxDL.SetWindowText("Unlim.");
  172.         m_ebMaxDL.EnableWindow(FALSE);
  173.     }
  174.  
  175.     SetModified();
  176. }
  177.  
  178. void CPrefDownload::OnChangeEditMaxDl() 
  179. {
  180.     SetModified();
  181. }
  182.  
  183. void CPrefDownload::OnCheckClearDl() 
  184. {
  185.     SetModified();    
  186. }
  187.  
  188. void CPrefDownload::OnChangeEditTimeoutDl() 
  189. {
  190.     SetModified();    
  191. }
  192.  
  193. void CPrefDownload::OnCheckResume() 
  194. {
  195.     SetModified();
  196. }
  197.  
  198. BOOL CPrefDownload::OnApply() 
  199. {
  200.     CString store;
  201.  
  202.     // Save downloads setting
  203.     m_ebSaveDir.GetWindowText(store);
  204.     Doc->m_DownloadDir = store;
  205.  
  206.     // Max simultaneous downloads
  207.     if(m_chkMaxDL.GetCheck())
  208.     {
  209.         m_ebMaxDL.GetWindowText(store);
  210.         
  211.         if(store != "")
  212.             Doc->m_MaxDownloads = atoi(store);
  213.     }
  214.     else
  215.         Doc->m_MaxDownloads = 0;
  216.  
  217.     // Auto clear downloads
  218.     if(m_chkClearDL.GetCheck())
  219.         Doc->m_AutoClearDL = 1;
  220.     else
  221.         Doc->m_AutoClearDL = 0;
  222.  
  223.     // Timeout of download length
  224.     m_ebTimeoutDL.GetWindowText(store);
  225.         
  226.     if(store != "")
  227.         Doc->m_TimeoutDownload = atoi(store);
  228.  
  229.     // Resume downloads
  230.     if(m_chkResume.GetCheck())
  231.         Doc->m_ResumeDL = 1;
  232.     else
  233.         Doc->m_ResumeDL = 0;
  234.  
  235.     return CPropertyPage::OnApply();
  236. }
  237.  
  238.  
  239.